package beanstao.util.type.base;

import java.lang.reflect.Array;

import beanstao.util.Strings;
import beanstao.util.Util;
import beanstao.util.exception.technical.util.reflect.FailToCastObjectException;
import beanstao.util.type.Castor;

public class String2Array extends Castor<String, Object>
{

	public String2Array()
	{
		this.fromClass = String.class;
		this.toClass = Array.class;
	}

	@Override
	public Object cast(String src, Class<?> toType, String... args) throws FailToCastObjectException
	{
		if (Strings.isQuoteByIgnoreBlank(src, '[', ']'))
		{
			// return Json.fromJson(toType, src);
		}
		String[] ss = Strings.splitIgnoreBlank(src);
		return Util.array2array(ss, toType.getComponentType());
	}

}
